/**
 * 
 */
package com.wuneng.commonlibrary.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * @Title: SharedPreferencesCommon
 * @Description:
 * @Company: www.cari.com.cn
 * @author zhouzhou
 * @date 2015-9-24 上午11:08:14
 */
public class SharedPreferencesHelper {

	public static void SetBoolean(Context context, String key, boolean flag) {
		SharedPreferences sp = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
		Editor edit = sp.edit();
		edit.putBoolean(key, flag);
		edit.commit();
	}

	public static boolean GetBoolean(Context context, String key, boolean defaultValue) {
		SharedPreferences sp = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
		boolean b = sp.getBoolean(key, defaultValue);
		return b;
	}


	/**
	 * 向SharedPreferences中存储指定值
	 * 
	 * @param context
	 * @param key
	 * @param value
	 */
	public static void SetValue(Context context, String key, String value) {
		SharedPreferences sp = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
		Editor ed = sp.edit();
		ed.putString(key, value);
		ed.commit();
	}

	/**
	 * 获取存储SharedPreferences中的值
	 * 
	 * @param context
	 * @param key
	 * @param DefultValue
	 * @return
	 */
	public static String GetValue(Context context, String key, String DefultValue) {
		SharedPreferences sp = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
		DefultValue = sp.getString(key, DefultValue);
		return DefultValue;
	}

	/**
	 * 向指定的SharedPreferences中存储值
	 * 
	 * @param context
	 * @param spName
	 * @param key
	 * @param value
	 */
	public static void SetValue(Context context, String spName, String key, String value) {
		SharedPreferences sp = context.getSharedPreferences(spName, Context.MODE_PRIVATE);
		Editor ed = sp.edit();
		ed.putString(key, value);
		ed.commit();
	}

	/**
	 * 从指定的SharedPreference中取值
	 * 
	 * @param context
	 * @param spName
	 * @param key
	 * @param DefultValue
	 * @return
	 */
	public static String GetValue(Context context, String spName, String key, String DefultValue) {
		SharedPreferences sp = context.getSharedPreferences(spName, Context.MODE_PRIVATE);
		DefultValue = sp.getString(key, DefultValue);
		return DefultValue;
	}
}
